package E2016;

class resul {
    static int[] sum = new int[19];
}
class add implements Runnable {
    int a;

    @Override
    public void run() {
        for (int i = 0; i < 19; i++) {
            a += (i + 1) * (i + 2);
            resul.sum[i] += a;
            System.out.println("a线程累加结果为" + resul.sum[i]);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class out implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 19; i++) {
            System.out.println("b线程读取a线程的结果为" + resul.sum[i]);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
public class Exam1_1 {
    public static void main(String[] args) {
        new Thread(new add(), "a").start();
        new Thread(new out(), "b").start();
    }
}
